#!/usr/bin/php -q
<?php
set_time_limit(0);
// $cookie_jar = ('/tmp/wlyc_cookie');
$cookie_jar = ('D:/xampp/htdocs/wlyc/tmp/wlyc_cookie');
unlink($cookie_jar);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://114.251.109.215/wlyc/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
$return = curl_exec($ch);
curl_close($ch);
preg_match('#__VIEWSTATE" value="(.*?)" />#iU',$return,$vs);
preg_match('#__EVENTVALIDATION" value="(.*?)" />#iU',$return,$ev);

$ch1 = curl_init();
curl_setopt($ch1, CURLOPT_URL, 'http://114.251.109.215/wlyc/image.aspx');
curl_setopt($ch1, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_HEADER, false);
$return = curl_exec($ch1);
curl_close($ch1);
$captcha = (trim(array_pop(explode("\t",array_pop(file($cookie_jar))))));

$request = '__EVENTVALIDATION='.urlencode($ev[1]).'&__VIEWSTATE='.urlencode($vs[1]).'&txtname=11028777&txtpwd=03150&yanzheng='.trim($captcha).'&button.x=18&button.y=15';
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://114.251.109.215/wlyc/XYYC21DR1.aspx');
curl_setopt($ch2, CURLOPT_POST, true);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$orders = curl_exec($ch2);
curl_close($ch2);

$ch3 = curl_init();
curl_setopt($ch3, CURLOPT_URL, 'http://114.251.109.215/wlyc/aspx/car/XYYC22.aspx');
curl_setopt($ch3, CURLOPT_HEADER, false);
curl_setopt($ch3, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch3, CURLOPT_COOKIEFILE, $cookie_jar);
$result = curl_exec($ch3);
curl_close($ch3);
echo str_replace('<head>','<head><base href="http://114.251.109.215/wlyc/aspx/car/" />',$result);
